package cn.heyige.backend.controller;

import cn.heyige.backend.common.CommResponse;
import cn.heyige.backend.facade.ApiKeyMonitorFacade;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * APIKEY监控控制器
 */
@RestController
@RequestMapping("api/monitor")
@RequiredArgsConstructor
@Tag(name = "API监控", description = "API密钥监控相关接口")
public class ApiKeyMonitorController {

    private final ApiKeyMonitorFacade apiKeyMonitorService;

    /**
     * 手动触发API KEY状态检查
     */
    @PostMapping("apiKey/check")
    @Operation(summary = "手动检查API密钥状态", description = "手动触发API密钥状态检查")
    public CommResponse<Map<String, Object>> manualCheckApiKeyStatus() {
        apiKeyMonitorService.manualCheckApiKeyStatus();
        Map<String, Object> result = Map.of(
                "success", true,
                "message", "API KEY状态检查已触发"
        );
        return CommResponse.ok(result);
    }

    /**
     * 获取服务状态信息
     */
    @GetMapping("apiKey/status")
    @Operation(summary = "获取服务状态信息", description = "获取API密钥和服务状态信息")
    public CommResponse<Map<String, Object>> getServiceStatusInfo() {
        Map<String, Object> statusInfo = apiKeyMonitorService.getServiceStatusInfo();
        Map<String, Object> result = Map.of(
                "success", true,
                "data", statusInfo
        );
        return CommResponse.ok(result);
    }
}